/*
 * @lc app=leetcode.cn id=682 lang=typescript
 *
 * [682] 棒球比赛
 */

// @lc code=start
function calPoints(ops: string[]): number {
    let ValidPoints: number[] = [];
    ops.forEach((i) => {
        switch (i) {
            case "+":
                ValidPoints.push(
                    ValidPoints[ValidPoints.length - 1] +
                        ValidPoints[ValidPoints.length - 2]
                );
                return;
            case "C":
                ValidPoints.pop();
                return;
            case "D":
                ValidPoints.push(ValidPoints[ValidPoints.length - 1] * 2);
                return;

            default:
                ValidPoints.push(parseInt(i));
        }
    });
    return ValidPoints.reduce((a, b) => a + b, 0);
}
// @lc code=end
